#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include "lab52.h" // 请不要删除本行头文件，否则检查不通过

extern int CurrentCnt; // 请不要删除本行的全局变量声明，否则检查不通过


bool insert_item(GoodsList *L, GoodsInfo goodsInfo, int choice){
    CurrentCnt++;
    if(choice == 0) //尾插
    {
        GoodsList *head =L;
        while(head->next!=NULL) 
        {
            head = head ->next;
        }
        GoodsList *tmp = malloc(sizeof(GoodsList));
        if(tmp==NULL) return false;
        else 
        {
            tmp ->data = goodsInfo;
            tmp ->next = NULL;
            head ->next = tmp;
            return true;
        }
    }
    else 
    {
        GoodsList *head =L;
        int cnt = 0;
        do
        {
            if(cnt == choice - 1)
            {
                GoodsList *tmp = malloc(sizeof(GoodsList));
                if(tmp==NULL) return false;
                tmp ->next  = head ->next;
                tmp ->data = goodsInfo;
                head ->next = tmp;
                return true;
            }
            cnt++;
            head = head ->next;
        }while(head ->next!=NULL);
        return false;
    }
    
}

